//---------------------------------------------------------------------
//
// Kinect.cpp : Defines the initialization routines for the plugin DLL.
//
//---------------------------------------------------------------------
#include "CKAll.h"
#include "KinectManager.h"

CKERROR InitInstance(CKContext* context);
CKERROR ExitInstance(CKContext* context);

#define PLUGIN_COUNT 2
#define KINECT_BEHAVIOR_GUID CKGUID(0x875a86ec, 0x0e9825bc)


CKPluginInfo g_PluginInfo[PLUGIN_COUNT];

int CKGetPluginInfoCount() {
	return PLUGIN_COUNT;
}

CKPluginInfo* CKGetPluginInfo(int Index)
{
	int Plugin = 0;
	g_PluginInfo[Plugin].m_Author			= "gjfeilipu";
	g_PluginInfo[Plugin].m_Description		= "kinect plugin for virtools";
	g_PluginInfo[Plugin].m_Extension		= "";
	g_PluginInfo[Plugin].m_Type				= CKPLUGIN_BEHAVIOR_DLL;
	g_PluginInfo[Plugin].m_Version			= 0x00000001;
	g_PluginInfo[Plugin].m_InitInstanceFct	= NULL;
	g_PluginInfo[Plugin].m_GUID				= KINECT_BEHAVIOR_GUID;
	g_PluginInfo[Plugin].m_Summary			= "Enter your summary here";

	Plugin++;
	g_PluginInfo[Plugin].m_Author			= "gjfeilipu";
	g_PluginInfo[Plugin].m_Description		= "kinect manager for virtools";
	g_PluginInfo[Plugin].m_Extension		= "";
	g_PluginInfo[Plugin].m_Type				= CKPLUGIN_MANAGER_DLL;
	g_PluginInfo[Plugin].m_Version			= 0x00000001;
	g_PluginInfo[Plugin].m_InitInstanceFct	= InitInstance;
	g_PluginInfo[Plugin].m_ExitInstanceFct	= ExitInstance;
	g_PluginInfo[Plugin].m_GUID				= KINECT_MANAGER_GUID;
	g_PluginInfo[Plugin].m_Summary			= "Kinect manager";
	return &g_PluginInfo[Index];
}

//  If no manager is used in the plugin 
//	these functions are optional and can be exported.
//  Virtools will call 'InitInstance' when loading the behavior library
//  and 'ExitInstance' when unloading it.
//	It is a good place to perform Attributes Types declaration, 
//  registering new enums or new parameter types.

CKERROR InitInstance(CKContext* context)
{
	CKParameterManager* pm = context->GetParameterManager();

	pm->RegisterNewEnum(GUID_NUI_TRACKED_SKELETONS_ENUM, 
		"NuiTrackedSkeletonsEnum", 
		"TRACKED_SKELETONS_DEFAULT,TRACKED_SKELETONS_NEAREST1,TRACKED_SKELETONS_NEAREST2,TRACKED_SKELETONS_STICKY1,TRACKED_SKELETONS_STICKY2");
	pm->RegisterNewFlags(GUID_NUI_INITIALIZE_FLAG,
		"NuiInitialzeFlag", "USES_COLOR=2,USES_SKELETON=8,USES_DEPTH=32,DEPTH_PLAYER_INDEX=1,HIGH_QUALITY_COLOR=64");
	
	new KinectManager(context);
	
	return CK_OK;
}

CKERROR ExitInstance(CKContext* context)
{
	// This function will only be called if the dll is unloaded explicitely 
	// by a user in Virtools Dev interface
	// Otherwise the manager destructor will be called by Virtools runtime directly
	delete context->GetManagerByGuid(KINECT_MANAGER_GUID);
	return CK_OK;
}

void RegisterBehaviorDeclarations(XObjectDeclarationArray *reg)
{
	RegisterBehavior(reg, FillBehaviorInitKinectDecl);
	RegisterBehavior(reg, FillBehaviorSkeletonPosDecl);
	RegisterBehavior(reg, FillBehaviorGetCameraAngleDecl);
	RegisterBehavior(reg, FillBehaviorSetCameraAngleDecl);
	RegisterBehavior(reg, FillBehaviorGetAccelerationDecl);
}


